
import sys
import cStringIO


strHex = '0123456789abcdef'

def ByteToHex(b):
    global strHex
    return '0' + strHex[b >> 4] + strHex[b & 0x0F]


def main(argv):
    if len(argv) < 2:
        print "Usage: BinToHex <FileName>"
        return

    fileName = argv[1]
    #fileName = "C:\\VCProj\\ShellCode\\my_code\\Release\\test.bin"

    f = open(fileName, mode='rb')
    data = f.read()
    f.close()


    strs = cStringIO.StringIO()
    row = 0
    for c in data:
        bit = (ByteToHex(ord(c)) + 'h')
        if (row == 0):
            strs.write("db " + bit)
            row += 1
        elif (row == 20):
            row = 0
            strs.write("," + bit +"\n")
        else:
            strs.write(',' + bit)
            row += 1
            
    print strs.getvalue()


if __name__ == '__main__':
    main(sys.argv)
